package com.zut.blocks.web.controller;

import com.zut.blocks.base.common.CommonResponse;
import com.zut.blocks.base.common.request.CourseGradeRequest;
import com.zut.blocks.base.controller.GenericController;
import com.zut.blocks.base.domain.CourseGrade;
import com.zut.blocks.service.grade.CourseGradeService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/course/grade")
public class CourseGradeController extends GenericController<CourseGrade, Integer, CourseGradeService> {

    @Resource
    CourseGradeService courseGradeService;

    @GetMapping("/all")
    public CommonResponse<List<CourseGrade>> findAll(CourseGradeRequest request) {
        Page<CourseGrade> courseGrades = courseGradeService.findAll(request);
        return CommonResponse.success(courseGrades.getContent(), courseGrades.getTotalElements());
    }

    @GetMapping
    public List<CourseGrade> findByCourseId(Integer courseId) {
        return courseGradeService.getByCourseId(courseId);
    }

    @PostMapping
    public CourseGrade saveCourseGrade(CourseGrade courseGrade) {
        return courseGradeService.save(courseGrade);
    }

    @PostMapping("/delete")
    public CommonResponse<Integer> deleteCourseGrade(Integer id) {
        return CommonResponse.success(courseGradeService.delete(id));
    }

    @PostMapping("/add")
    public CommonResponse<Integer> addCourseGrade(CourseGrade courseGrade){
        return CommonResponse.success(courseGradeService.add(courseGrade));
    }
}
